import { createRouter, createWebHistory } from 'vue-router';
import Home from '../views/Home.vue';
import { PermissionsPage } from '../assets/js/permission';
const routes = [
  // {
  //   path: "/",
  //   redirect: "/homepage",
  // },
  {
    path: '/',
    redirect: '/index',
  },
  {
    path: '/',
    name: 'Home',
    component: Home,
    children: [
      {
        path: '/demo',
        name: 'demo',
        meta: {
          title: '测试页面',
        },
        component: () =>
          import(/* webpackChunkName: "dashboard" */ '../views/demo.vue'),
      },
      {
        path: '/dashboard',
        name: 'dashboard',
        meta: {
          title: '首页A',
        },
        component: () =>
          import(/* webpackChunkName: "Dashboard" */ '../views/Dashboard.vue'),
      },
      {
        path: '/home1',
        name: 'home1',
        meta: {
          title: '智慧教室',
        },
        component: () =>
          import(
            /* webpackChunkName: "Dashboard" */ '../pages/homepage/home1.vue'
          ),
      },
      {
        path: '/home2',
        name: 'home2',
        meta: {
          title: '统一平台',
        },
        component: () =>
          import(
            /* webpackChunkName: "Dashboard" */ '../pages/homepage/home2.vue'
          ),
      },
      {
        path: '/homepage',
        name: 'homepage',
        meta: {
          title: '首页B',
        },
        component: () =>
          import(
            /* webpackChunkName: "homepage" */ '../pages/homepage/homepage.vue'
          ),
      },
      {
        path: '/homepageIrontower',
        name: 'homepageIrontower',
        meta: {
          title: '铁塔首页',
        },
        component: () =>
          import(
            /* webpackChunkName: "homepage" */ '../pages/homepage/homepageIrontower.vue'
          ),
      },
      {
        path: '/hingCollegeIndex',
        name: 'hingCollegeIndex',
        meta: {
          title: '兴才学院',
        },
        component: () =>
          import(
            /* webpackChunkName: "hingCollegeIndex" */ '../pages/homepage/hingCollegeIndex.vue'
          ),
      },
      {
        path: '/HonfaHome',
        name: 'HonfaHome',
        meta: {
          title: '宏发首页',
        },
        component: () =>
          import(
            /* webpackChunkName: "HonfaHome" */ '../pages/homepage/HonfaHome.vue'
          ),
      },
      {
        path: '/controlPanelIndex',
        name: 'controlPanelIndex',
        meta: {
          title: '统一控制台',
        },
        component: () =>
          import(
            /* webpackChunkName: "controlPanelIndex" */ '../pages/homepage/controlPanelIndex.vue'
          ),
      },
      {
        path: '/cityCollegeIndex',
        name: 'cityCollegeIndex',
        meta: {
          title: '城市学院',
        },
        component: () =>
          import(
            /* webpackChunkName: "dashboard" */ '../pages/homepage/cityCollegeIndex.vue'
          ),
      },
      {
        path: '/fudanHospital',
        name: 'fudanHospital',
        meta: {
          title: '复旦中山医院',
        },
        component: () =>
          import(
            /* webpackChunkName: "dashboard" */ '../pages/homepage/fudanHospital.vue'
          ),
      },
      {
        path: '/engineeCollege',
        name: 'engineeCollege',
        meta: {
          title: '工学院首页',
        },
        component: () =>
          import(
            /* webpackChunkName: "dashboard" */ '../pages/homepage/engineeCollege.vue'
          ),
      },
      {
        path: '/electricalFireIndex',
        name: 'electricalFireIndex',
        meta: {
          title: '电气火灾',
        },
        component: () =>
          import(
            /* webpackChunkName: "dashboard" */ '../pages/homepage/electricalFireIndex.vue'
          ),
      },
    ],
  },
  {
    path: '/index',
    name: 'index',
    meta: {
      title: '宏发首页',
    },
    component: () =>
      import(/* webpackChunkName: "HonfaHome" */ '../pages/homepage/hf3d.vue'),
  },
  {
    path: '/register',
    name: 'Register',
    meta: {
      title: '登录',
    },
    component: () =>
      import(/* webpackChunkName: "register" */ '../views/Register.vue'),
  },
  {
    path: '/login',
    name: 'Login',
    meta: {
      title: '登录',
    },
    component: () =>
      import(/* webpackChunkName: "login" */ '../views/Login.vue'),
  },
  {
    path: '/fullScreenMap',
    name: 'fullScreenMap',
    meta: {
      title: '地图查看',
    },
    component: () =>
      import(
        /* webpackChunkName: "dashboard" */ '../pages/homepage/fullScreenMap.vue'
      ),
  },
  {
    path: '/fullScreenIrontower',
    name: 'fullScreenIrontower',
    meta: {
      title: '地图查看',
    },
    component: () =>
      import(
        /* webpackChunkName: "dashboard" */ '../pages/homepage/fullScreenIrontower.vue'
      ),
  },
  {
    path: '/fullCityCollege',
    name: 'fullCityCollege',
    meta: {
      title: '城市学院',
    },
    component: () =>
      import(
        /* webpackChunkName: "dashboard" */ '../pages/homepage/fullCityCollege.vue'
      ),
  },
  {
    path: '/buildIndex',
    name: 'buildIndex',
    meta: {
      title: '首页A',
    },
    component: () =>
      import(/* webpackChunkName: "Dashboard" */ '../views/buildIndex.vue'),
  },
  {
    path: '/fullHingCollege',
    name: 'fullHingCollege',
    meta: {
      title: '兴才学院',
    },
    component: () =>
      import(
        /* webpackChunkName: "fullHingCollege" */ '../pages/homepage/fullHingCollege.vue'
      ),
  },
  {
    path: '/fullcontrolPanel',
    name: 'fullcontrolPanel',
    meta: {
      title: '统一控制台',
    },
    component: () =>
      import(
        /* webpackChunkName: "fullcontrolPanel" */ '../pages/homepage/fullcontrolPanel.vue'
      ),
  },
  {
    path: '/fullElectricalFire',
    name: 'fullElectricalFire',
    meta: {
      title: '电气火灾',
    },
    component: () =>
      import(
        /* webpackChunkName: "fullElectricalFire" */ '../pages/homepage/fullElectricalFire.vue'
      ),
  },
];
const router = createRouter({
   mode: 'history',
//   mode: 'hash',
  base: 'lighthouse',
  history: createWebHistory(),
  routes,
});

router.beforeEach((to, from, next) => {
  document.title =
    localStorage.getItem('projectName') ||
    `${to.meta.title} | 数字物联综合管理平台`;
    const role = localStorage.getItem("ms_username");
    if (!role && to.path !== "/index") {
      next("/index");
    } else if (to.meta.permission) {
      // 如果是管理员权限则可进入，这里只是简单的模拟管理员权限而已
      role === "admin" ? next() : next("/403");
    } else {
  next();
    }
});

export default router;
